#pragma once

namespace gtl
{
	namespace patterns
	{
		template<class Component, class Flyweight>
		class flyweight : public Component
		{
		public:
			typedef Component component_type;
			typedef Flyweight flyweight_type;

		public:
			flyweight() { _flyweightptr = NULL; }
			virtual ~flyweight() {}

		public:
			flyweight_type* get_flyweight(void) { return _flyweightptr; }
			void attach(flyweight_type* flyweightptr) {
				flyweight_type* ptr = flyweightptr;
				_flyweightptr = flyweightptr; 
				if(NULL != ptr)
					delete ptr;
			}

		protected:
			flyweight_type* _flyweightptr;
		};
	}
}